<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 创建一个父对象的构造函数
      function Parent() {
        this.name = 'Parent'
      }

      // 给父对象的原型添加方法
      Parent.prototype.sayHello = function () {
        console.log(`Hello, my name is ${this.name}`)
      }

      // 创建一个子对象的构造函数
      function Child() {
        this.name = 'Child'
      }

      // 将子对象的原型指向父对象的实例
      Child.prototype = new Parent()

      // 创建子对象的实例
      const child = new Child()

      child.sayHello() // 输出：Hello, my name is Child
    </script>
  </body>
</html>
